package server.models;

import java.util.*;

import server.doc.xml.XMLUserProfile;

import common.models.MvcModel;
import common.types.GenderType;

public class UserProfile extends MvcModel{
	
	private static final long serialVersionUID = -3980386053303394546L;
	
	private int userID;
	private String name, password;
	private GenderType gender;
	private int age;
	private ArrayList<Integer> friendList;
	
	/* existed user profile
	 * created by a given uid
	 */
	public UserProfile(int uid, String p, String n, GenderType g, int a, ArrayList<Integer> friends) {
		userID = uid;  password = p;
		name = n;  gender = g;  age = a;
		friendList = friends;
	}
	
	/* new user profile
	 * uid is automatically generated
	 */
	public UserProfile(String p, String n, GenderType g, int a) {
		this(XMLUserProfile.getInstance().newUserID(), p, n, g, a, new ArrayList<Integer>());
	}
	
	public int getUserID() { return userID; }
	
	public String getPassword() { return password; }
	public void setPassword(String pwd) { password = pwd; }
	
	public String getName() { return name; }
	public void setName(String n) { name = n; }
	
	public GenderType getGender() { return gender; }
	public void setGender(GenderType g) { gender = g; }
	
	public int getAge() { return age; }
	public void setAge(int a) { age = a; }
	
	public ArrayList<Integer> getFriends() { return friendList; }
	public void setFriends(ArrayList<Integer> friends) { friendList = friends; }
	public void addFriend(int uid, int group) {
		if (new XMLUserProfile().getUser(uid) != null)
			friendList.add(new Integer(uid));
		else
			throw new Error("User #" + Integer.toString(uid) + " doesn't exist");
	}
	public void deleteFriend(int uid) {
		if (friendList.contains(new Integer(uid)))
			friendList.remove(new Integer(uid));
		else
			throw new Error("Don't have a friend #" + Integer.toString(uid));
	}
	
}
